<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Arduino FDK AAC Encoder and Decoder Library: Arduino AAC Encoding and Decoding Library</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Arduino FDK AAC Encoder and Decoder Library
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Arduino AAC Encoding and Decoding Library </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="md_README"></a> I was looking for a way to encode sound PCM data to the AAC or MPEG data format on some Arduino Devices. That's when I found the <a href="https://en.wikipedia.org/wiki/Fraunhofer_FDK_AAC">Fraunhofer FDK AAC library</a>.</p>
<p>The Android-targeted implementation of the Fraunhofer AAC can be used for encoding and decoding, uses fixed-point math and is optimized for encoding on embedded devices/mobile phones. The library is currently limited to 16-bit PCM input. So this seems to be the perfect match to be used in Arduino based Microcontrollers.</p>
<p>I have forked the <a href="https://github.com/mstorsjo/fdk-aac/tree/v2.0.1">fdk-aac</a> project, converted it to an Arduino library and provided a simple Arduino friendly API. The only caveat is, that I have removed all optimized processor specific code (e.g. for ARM, 386 and mips), so that it will compile with the same code on all environements.</p>
<h1><a class="anchor" id="autotoc_md1"></a>
Decoding Example</h1>
<div class="fragment"><div class="line">#include &quot;AACDecoderFDK.h&quot;</div>
<div class="line">#include &quot;BabyElephantWalk60_aac.h&quot;</div>
<div class="line"> </div>
<div class="line">using namespace aac_fdk;</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line">void dataCallback(CStreamInfo &amp;info, INT_PCM *pcm_data, size_t len) {</div>
<div class="line">    int channels = info.numChannels;</div>
<div class="line">    for (size_t i=0; i&lt;len; i+=channels){</div>
<div class="line">        for (int j=0;j&lt;channels;j++){</div>
<div class="line">            Serial.print(pcm_data[i+j]);</div>
<div class="line">            Serial.print(&quot; &quot;);</div>
<div class="line">        }</div>
<div class="line">        Serial.println();</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">AACDecoderFDK aac(dataCallback);</div>
<div class="line"> </div>
<div class="line">void setup() {</div>
<div class="line">    Serial.begin(115200);</div>
<div class="line">    aac.begin();</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">void loop() {</div>
<div class="line">    Serial.println(&quot;writing...&quot;);</div>
<div class="line">    aac.write(BabyElephantWalk60_aac, BabyElephantWalk60_aac_len);    </div>
<div class="line"> </div>
<div class="line">    // restart from the beginning</div>
<div class="line">    delay(2000);</div>
<div class="line">    aac.begin();</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md2"></a>
Encoding Example</h1>
<div class="fragment"><div class="line">#include &quot;AACEncoderFDK.h&quot;</div>
<div class="line">#include &lt;stdlib.h&gt;     /* srand, rand */</div>
<div class="line"> </div>
<div class="line">using namespace aac_fdk;</div>
<div class="line"> </div>
<div class="line">void dataCallback(uint8_t *aac_data, size_t len) {</div>
<div class="line">    Serial.print(&quot;AAC generated with &quot;);</div>
<div class="line">    Serial.print(len);</div>
<div class="line">    Serial.println(&quot; bytes&quot;);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">AACEncoderFDK aac(dataCallback);</div>
<div class="line">AudioInfo info;</div>
<div class="line">int16_t buffer[512];</div>
<div class="line"> </div>
<div class="line">void setup() {</div>
<div class="line">    Serial.begin(115200);</div>
<div class="line"> </div>
<div class="line">    info.channels = 1;</div>
<div class="line">    info.sample_rate = 10000;</div>
<div class="line">    aac.begin(info);</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line">void loop() {</div>
<div class="line">    Serial.println(&quot;writing 512 samples of random data&quot;);</div>
<div class="line">    for (int j=0;j&lt;512;j++){</div>
<div class="line">        buffer[j] = (rand() % 100) - 50;         </div>
<div class="line">    }</div>
<div class="line">    aac.write(buffer, 512);</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md3"></a>
Installation</h1>
<p>You can download the library as zip and call include Library -&gt; zip library. Or you can git clone this project into the Arduino libraries folder e.g. with</p>
<div class="fragment"><div class="line">cd  ~/Documents/Arduino/libraries</div>
<div class="line">git clone pschatzmann/arduino-fdk-aac.git</div>
</div><!-- fragment --><h1><a class="anchor" id="autotoc_md4"></a>
Class Documentation</h1>
<p>The <a href="https://pschatzmann.github.io/arduino-fdk-aac/html/">generated class documentation</a> can be found here.</p>
<h1><a class="anchor" id="autotoc_md5"></a>
Compile Issues / Supported Architectures</h1>
<p>On some processors we get compile errors because the arrays are too big. <br  />
 Please uncomment the #define PIT_MAX_MAX line in the AACConstantsOverride.h file.</p>
<p>All examples have been written and tested on a ESP32. The basic funcationality of the encoder and decoder however should work on all Arduino Devices and is independent from the processor.</p>
<h1><a class="anchor" id="autotoc_md6"></a>
Copyright</h1>
<p>Please read the included [NOTICE](NOTICE). </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
